package com.jwaoo.mobile.view.register.fragment;

import android.content.Context;
import android.view.View;
import android.widget.EditText;

import com.bigkoo.pickerview.TimePickerView;
import com.dx.as.common.FragmentUtils;
import com.dx.as.fragment.TFragment;
import com.dx.as.utils.DateUtil;
import com.jwaoo.mobile.R;
import com.jwaoo.mobile.view.register.IParamListener;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by jwaoo on 2017/11/22.
 */

public class NickNameFragment extends TFragment {
    private EditText edt_age;
    private IParamListener listener;
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        listener = (IParamListener) context;
    }
    @Override
    public void initView() {
        edt_age = findView(R.id.edt_age);
        edt_age.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onSelected();
            }
        });
        findView(R.id.btn_next).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showKeyboard(false);
                String nickName = ((EditText)findView(R.id.edt_nickname)).getText().toString();
                listener.saveNickName(nickName);
                FragmentUtils.goToFragment(getActivity(),HeadFragment.class,R.id.register_container);
            }
        });

        findView(R.id.btn_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FragmentUtils.goBackFragment(getActivity(),CountryFragment.class,R.id.register_container,NickNameFragment.class);
            }
        });
    }

    @Override
    public int setLayoutI() {
        return R.layout.fragment_nickname;
    }

    @Override
    public void dataOpion() {

    }

    @Override
    public void initRpo() {

    }

    private void onSelected(){
        //时间选择器
        TimePickerView pvTime = new TimePickerView.Builder(getActivity(), new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                String birthday = DateUtil.formatDateYYMMDD(date);
                edt_age.setText(birthday);
                listener.saveAge(birthday);
            }
        })
                .setLabel("","","","","","")
                .isCyclic(true)
                .setType(new boolean[]{true,true,true,false,false,false})
                .build();
        pvTime.setDate(Calendar.getInstance());//注：根据需求来决定是否使用该方法（一般是精确到秒的情况），此项可以在弹出选择器的时候重新设置当前时间，避免在初始化之后由于时间已经设定，导致选中时间与当前时间不匹配的问题。
        pvTime.show();
    }
}
